<template>
  <j-modal
    title="商机列表"
    :width="width"
    :visible="checkVisible"
    switchFullscreen
    @cancel="checkVisible = false"
    :footer="null"
  >
    <!-- <a-modal :width="width" title="商机列表" :visible="checkVisible" @ok="" @cancel="checkVisible = false" :footer="null"> -->
    <a-table
      :columns="columnsPer"
      :data-source="businessList"
      bordered
      @change="handleTableChange"
      :pagination="{ pageSize: 100 }"
      :scroll="{ x: 1300, y: 550 }"
    >
      <template slot="businessName" slot-scope="text, record">
        <a-tooltip placement="top">
          <template slot="title">
            <span>{{ record.businessName }}</span>
          </template>
          <span class="ellipsis"
            ><a @click="() => handleShow(record.businessId)">{{ record.businessName }}</a></span
          >
        </a-tooltip>
      </template>
      <span slot="estimatedSalesAmount" slot-scope="text, record">
        {{ record.estimatedSalesAmount | amountFormat }}
      </span>
      <span slot="successEstimatedSalesAmount" slot-scope="text, record">
        {{ record.successEstimatedSalesAmount | amountFormat }}
      </span>
    </a-table>
  </j-modal>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'

import { mixinDevice } from '@/utils/mixin'
export default {
  name: 'customerList',
  props: {},
  components: {},
  data() {
    return {
      queryParam: {
        typeId: '1',
      },
      /* 排序参数 */
      isorter: {
        column: '-createTime',
        order: '',
      },
      ipagination: {
        current: 1,
        pageSize: 600,
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        total: 0,
      },
      columnsPer: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 100,
          align: 'center',
          fixed: true,
          customRender: function (t, r, index) {
            if (r.rank == '汇总') {
              return '汇总'
            } else {
              return parseInt(index) + 1
            }
          },
        },
        {
          title: '客户名称',
          width: 200,
          dataIndex: 'customerId_dictText',
          align: 'center',
          ellipsis: true,
          sorter: true,
        },
        {
          title: '商机名称',
          width: 200,
          dataIndex: 'businessName',
          align: 'center',
          ellipsis: true,
          scopedSlots: { customRender: 'businessName' },
          sorter: true,
        },
        {
          title: '冷冻（托）',
          width: 150,
          dataIndex: 'estimatedFreeze',
          align: 'center',
          sorter: true,
        },
        {
          title: '冷藏（托）',
          width: 150,
          dataIndex: 'estimatedRefrigerate',
          align: 'center',
          sorter: true,
        },
        {
          title: '恒温（托）',
          width: 150,
          dataIndex: 'estimatedConstant',
          align: 'center',
          sorter:true,
        },
        {
          title: '常温（托）',
          width: 150,
          dataIndex: 'estimatedNormal',
          align: 'center',
          sorter: true,
        },
        {
          title: '客户经理',
          width: 150,
          dataIndex: 'ownerUserId_dictText',
          align: 'center',
          sorter:true,
        },
        {
          title: '所属BU',
          width: 150,
          dataIndex: 'ownerUserId_bu',
          align: 'center',
        },
        {
          title: '创建时间',
          width: 200,
          dataIndex: 'createTime',
          align: 'center',
          sorter: true,
        },
      ],
      businessList: [],
      width: '70%',
      checkVisible: false,
      url: {
        list: '/online/test/pagingCrmBusinessItemForType',
      },
    }
  },
  created() {},
  methods: {
    show(record, param) {
      this.queryParam.createTime_fld0_value = param.createTime_fld0_value
      this.queryParam.createTime_fld1_value = param.createTime_fld1_value
      this.queryParam.inventoryId = record.warehouseId
//      this.queryParam.statusIdInList = '0,1,2,3,4,5'
      this.queryParam.statusIdInList = '0,1,2,3,4'
      this.businessList = []
      this.checkVisible = true
      this.loadData()
    },
    loadData() {      
      let qp ={}
      var param = Object.assign(qp, this.queryParam, this.isorter);
      param.pageNo = this.ipagination.current
      param.pageSize = this.ipagination.pageSize
      console.log(param)
      httpAction(this.url.list, param, 'post').then((res) => {
        if (res.success) {
          this.businessList = res.result.records || []
          this.ipagination.total = res.result.total
        }
      })
    },
    handleShow(businessId) {
      let param = {}
      param.isEditBusiness = false
      param.id = businessId
      this.$emit('handleShow', param)
    },
    handleTableChange(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field
        this.isorter.order = 'ascend' == sorter.order ? 'asc' : 'desc'
      }
      console.log(sorter)
      this.loadData()
    },
  },
}
</script>

<style lang="less" scoped>
/deep/ .ant-input {
  border-radius: 0;
}
/deep/ .ant-select {
  width: 100%;
}
/deep/ .ant-select-selection {
  border-radius: 0;
}
/deep/ .ant-modal-header {
  border-bottom: 1px solid #e8e8e8;
}
/deep/ .ant-table-thead > tr > th,
.ant-table-tbody > tr > td {
  padding: 10px 15px;
}
/deep/ .ant-modal-mask {
  z-index: 99 !important;
}
/deep/ .ant-modal-wrap {
  z-index: 99 !important;
}
</style>